#ifndef PLAYLISTMODEL_H
#define PLAYLISTMODEL_H

#include <QAbstractItemModel>

class QMediaPlaylist;

class PlaylistModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    enum Column
    {Title = 0, ColumnCount};

    //explicit PlaylistModel(QObject *parent = 0); explicit关键字用于修饰构造函数，表示显示调用
    PlaylistModel(QObject *parent = 0);

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &child) const;

    QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;

    QMediaPlaylist *playlist() const;
    void setPlaylist(QMediaPlaylist *playlist);

    bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole);

private slots:
    void beginInsertItems(int start, int end); //顶部插入项目
    void endInsertItem(); //底部插入项目
    void beginRemoveItems(int start, int end); //顶部删除项目
    void endRemoveItems();
    void changeItems(int start, int end);


private:
    QMediaPlaylist *m_playlist;
    QMap<QModelIndex, QVariant> m_data;


};

#endif // PLAYLISTMODEL_H
